/**
 * Copyright © 2021-2025 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.ruoyi.cost.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.cost.domain.Account;
import com.ruoyi.cost.domain.Post;
import com.ruoyi.cost.service.AccountService;
import com.ruoyi.cost.service.UnitService;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/account/account")
public class AccountController extends BaseController {

    @Autowired
    private AccountService accountService;
    @Autowired
    private UnitService unitService;


    @GetMapping("list")
    public AjaxResult treeData(String index) {
        List<Account> list = Lists.newArrayList();
        if (index != null && !"".equals(index)){
            list = accountService.listFroUnit(index);
        }else {
            list = accountService.list();
        }
        for (Account account : list) {
            String unitType = account.getUnitType();
            Post byId = unitService.getById(unitType);
            account.setUnitType(byId.getName());
        }
        return success( list );

    }

}
